#include "../include/mutex.h"
#include <pthread.h>

//pthread_cond_t cond_sqlite;  //数据库线程
//pthread_cond_t cond_analysis;
pthread_cond_t cond_uart_cmd;        //写串口条件变量
pthread_cond_t cond_client_request;  //下行数据解析主线程
//pthread_cond_t cond_infrared;		 
pthread_cond_t cond_buzzer;			//A9蜂鸣器线程条件变量
pthread_cond_t cond_led;			//A9LED线程条件变量
pthread_cond_t cond_camera;			//A9摄像头条件变量
pthread_cond_t cond_sms;            //信息线程锁
pthread_cond_t cond_led;     //LED控制模块被唤醒条件变量
pthread_cond_t cond_m0_over_ctl;


//pthread_cond_t cond_uart;			//串口读写条件变量，读完发信号给写


/*pthread_cond_t cond_sms;
pthread_cond_t cond_refresh;
pthread_cond_t cond_refresh_updata;

pthread_mutex_t mutex_slinklist;
pthread_mutex_t mutex_sqlite;
pthread_mutex_t mutex_analysis;
pthread_mutex_t mutex_analysis_chaek_env;
*/
pthread_mutex_t mutex_uart_cmd;			//写zigbee串口锁
pthread_mutex_t mutex_client_request;	//下行数据解析主线程锁
//pthread_mutex_t mutex_infrared;			
pthread_mutex_t mutex_buzzer;            //A9板蜂鸣器线程
pthread_mutex_t mutex_led;				 //A9板LED线程
pthread_mutex_t mutex_camera;			 //A9板相机线程
pthread_mutex_t mutex_uart;              //zigbee串口读写锁
pthread_mutex_t recvdata_lock;          //共享内存线程锁
pthread_mutex_t mutex_m0_over_ctl;		//判断环境信息是否超多上限控制线程
pthread_mutex_t mutex_sms;              //短信线程锁
pthread_mutex_t mutex_led;          	//A9LED控制线程互斥锁
pthread_mutex_t mutex_limit;            //环境变量限定线程锁
/*pthread_mutex_t mutex_sms;
pthread_mutex_t mutex_refresh;
pthread_mutex_t mutex_refresh_updata;
pthread_mutex_t mutex_global;
pthread_mutex_t mutex_linklist;
*/

void mutex_init(void)
{
	pthread_mutex_init (&mutex_uart_cmd, NULL);
	pthread_mutex_init (&mutex_client_request, NULL);
	pthread_mutex_init (&mutex_buzzer, NULL);
	pthread_mutex_init (&mutex_led, NULL);
	pthread_mutex_init (&mutex_camera, NULL);
	pthread_mutex_init (&mutex_uart, NULL);
	pthread_mutex_init (&recvdata_lock, NULL);
	pthread_mutex_init (&mutex_m0_over_ctl, NULL);
	pthread_mutex_init (&mutex_sms, NULL);
	pthread_mutex_init (&mutex_limit, NULL);
	
	pthread_cond_init (&cond_uart_cmd, NULL);
	pthread_cond_init (&cond_client_request, NULL);
	pthread_cond_init (&cond_buzzer, NULL);
	pthread_cond_init (&cond_led, NULL);
	pthread_cond_init (&cond_camera, NULL);
	pthread_cond_init (&cond_sms,NULL);
	pthread_cond_init (&cond_m0_over_ctl,NULL);
	//pthread_cond_init (&cond_uart, NULL);
}

void mutex_destory(void)
{
	pthread_mutex_destroy (&mutex_camera);
	pthread_mutex_destroy (&mutex_led);
	pthread_mutex_destroy (&mutex_buzzer);
	pthread_mutex_destroy (&mutex_client_request);
	pthread_mutex_destroy (&mutex_uart_cmd);
	pthread_mutex_destroy (&mutex_uart);
	pthread_mutex_destroy (&recvdata_lock);
	pthread_mutex_destroy (&mutex_sms);
	pthread_mutex_destroy (&mutex_m0_over_ctl);
	pthread_mutex_destroy (&mutex_limit);

	pthread_cond_destroy (&cond_camera);
	pthread_cond_destroy (&cond_led);
	pthread_cond_destroy (&cond_buzzer);
	pthread_cond_destroy (&cond_uart_cmd);
	pthread_cond_destroy (&cond_camera);
	pthread_cond_destroy (&cond_sms);
	pthread_cond_destroy (&cond_m0_over_ctl);
	//pthread_cond_destroy (&cond_uart);
}
